import { PureComponent } from 'react';
import moment from 'moment';
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
    DatePicker
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select;


@Form.create()
class CreateForm extends PureComponent {
	
	constructor(props) {
	    super(props);
	    this.state = {
	    	
	    }
	}
 

	okHandle = () => {
		const { form,handleAddByTrain } = this.props;

	    form.validateFields((err, fieldsValue) => {
		        if (err) return;
			    form.resetFields();
			   	if(fieldsValue.training_start_time) {
	      			fieldsValue.training_start_time = moment(fieldsValue.training_start_time._d).format("YYYY-MM-DD");
	      		}
				if(fieldsValue.training_end_time) {
	      			fieldsValue.training_end_time = moment(fieldsValue.training_end_time._d).format("YYYY-MM-DD");
	      		}
			    handleAddByTrain(fieldsValue);
		});
	};
	
	
	resetButton = () => {

	};

  render() {
    const {form: {getFieldDecorator}, modalVisibleByTrain,handleModalVisibleByTrain} = this.props;

return (
    <Modal
width={800}
destroyOnClose
title="添加培训记录"
visible={modalVisibleByTrain}
onOk={this.okHandle}
onCancel={() => handleModalVisibleByTrain()}
afterClose={() => this.resetButton()}
>
<Form  layout="vertical">
    	<Row gutter={{ md: 8, lg: 24, xl: 48 }}>

	        <Col  md={12} sm={24}>
		        <FormItem  label="培训课程">
		            {getFieldDecorator('training_course', {
		            rules: [{ required: true, message: '请输入1-50位字符的课程名称', max: 50}],
		            })(<Input placeholder="1-50位字符" />)}
		        </FormItem>
	        </Col>
			    <Col md={12} sm={24}>
		          <FormItem  label="培训开始时间">
		              {getFieldDecorator('training_start_time')(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
		          </FormItem>
		      </Col>
		
    	</Row>
    	<Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    <Col md={12} sm={24}>
		          <FormItem  label="培训结束时间">
		              {getFieldDecorator('training_end_time')(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
		          </FormItem>
		      </Col>
	        <Col  md={12} sm={24}>
		        <FormItem  label="培训时长">
		            {getFieldDecorator('training_duration', {
		            rules: [{ required: true, message: '最多输入10位字符', max: 10}],
		            })(<Input placeholder="1-10位字符" />)}
		        </FormItem>
	        </Col>

    	</Row>
    	<Row gutter={{ md: 8, lg: 24, xl: 48 }}>

	        <Col  md={12} sm={24}>
		        <FormItem  label="培训机构名称">
		            {getFieldDecorator('training_mechanism_name', {
		            rules: [{ required: false, message: '最多输入10位字符', max: 10}],
		            })(<Input placeholder="1-10位字符" />)}
		        </FormItem>
	        </Col>
	        <Col  md={12} sm={24}>
		        <FormItem  label="考核结果">
		            {getFieldDecorator('examination_results', {
		            rules: [{ required: true, message: '最多输入50位字符', max: 50}],
		            })(<Input placeholder="1-50位字符" />)}
		        </FormItem>
	        </Col>
		
    	</Row>
    	<Row gutter={{ md: 8, lg: 24, xl: 48 }}>

	        <Col  md={12} sm={24}>
		        <FormItem  label="培训地点">
		            {getFieldDecorator('training_address', {
		            rules: [{ required: false, message: '最多输入50位字符', max: 50}],
		            })(<Input placeholder="1-50位字符" />)}
		        </FormItem>
	        </Col>
	        <Col  md={12} sm={24}>
		        <FormItem  label="培训方式">
		            {getFieldDecorator('training_type', {
		            rules: [{ required: true, message: '最多输入50位字符', max: 50}],
		            })(<Input placeholder="1-50位字符" />)}
		        </FormItem>
	        </Col>
		
    	</Row>

</Form>
</Modal>
);
  }

}

export default CreateForm;
